package com.woniuxy.lab.woniu_lab.mqListener;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.lab.woniu_lab.model.Charge;
import com.woniuxy.lab.woniu_lab.service.ChargeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Component
@RocketMQMessageListener(topic = "cancel_charge_topic",consumerGroup = "cancelCharge")
@Slf4j
public class CancelCharge implements RocketMQListener<String> {

    @Resource
    private ChargeService chargeService;

    @Override
    public void onMessage(String no) {
        log.info("充值状态查询{}",no);
        Charge charge = chargeService.getOne(new QueryWrapper<Charge>().eq("no", no).eq("status", "PAYING"));
        if (charge!=null){
            log.info("取消订单{}",no);
            charge.setExpireTime(LocalDateTime.now());
            charge.setStatus("FAIL");
            chargeService.updateById(charge);
        }
    }
}
